using System.Linq;
using Restbucks.Shared.Representations;
using Restbucks.Shared.Domain;

namespace Restbucks.Shared.Mappers
{
    public class OrderRepresentationMapper
    {
        public static OrderRepresentation GetRepresentation(Order order)
        {
            return new OrderRepresentation
                       {
                           Cost = order.CalculateTotal(),
                           Items = order.Items.Select<Item, ItemRepresentation>(ItemRepresentationMapper.GetRepresentation).ToList(),
                           Location = order.Location,
                           Status = order.Status,
                       };
        }

        public static Order GetDomainObject(OrderRepresentation orderRepresentation)
        {
            return new Order(orderRepresentation.Location, orderRepresentation.Items.Select<ItemRepresentation, Item>(ItemRepresentationMapper.GetDomainObject));
        }
    }
}